<template>
	<!-- 推广中心 -->
	<view class="page">
		<view class="top">
			<c-navBar title="推广中心" type="1" isTran color="#FFFFFF"></c-navBar>
			<image class="promotion_bg" src="/pages/my/static/promotion_bg.png" mode=""></image>
			<view class="info">
				<view class="info_l">
					<image class="header-img"
						:src="userInfo.avatar?vuex_imgUrl+userInfo.avatar:'/static/common/header-img.png'" />
					<view class="user">
						<view class="title">{{userInfo.nickname}}</view>
						<view class="phone">{{$fn.phoneEn(userInfo.phone)}} </view>
					</view>
				</view>
				<button class="record" @click="clickBtn">分享好友</button>
			</view>

			<view class="revenue">
				<view class="r_item">
					<view class="r_name">当前余额(元)</view>
					<view class="r_price">{{$fn.twoToFixed(userInfo.withdrawableAmount)}}</view>
				</view>
				<view class="r_item">
					<view class="r_name">今日收益(元)</view>
					<view class="r_price">{{$fn.twoToFixed(userInfo.todayEarnings)}}</view>
				</view>
				<view class="r_item">
					<view class="r_name">累计收益(元)</view>
					<view class="r_price">{{$fn.twoToFixed(userInfo.totalRevenue)}}</view>
				</view>
			</view>
			<view class="cash">
				<view class="c_top">
					<view class="c_item">
						<view class="c_name">提现中(元)</view>
						<view class="c_price">{{$fn.twoToFixed(userInfo.withdrawingAmount)}}</view>
					</view>
					<view class="c_line"></view>
					<view class="c_item">
						<view class="c_name">已提现(元)</view>
						<view class="c_price">{{$fn.twoToFixed(userInfo.withdrawAmount)}}</view>
					</view>
				</view>
				<view class="c_btm">
					<view class="c_btn c_btn1" @click="$fn.jumpPage('/pages/my/pages/balanceDetails')">余额明细</view>
					<view class="c_btn c_btn2"
						@click="$fn.jumpPage('/pages/my/pages/withdraw?amount='+userInfo.withdrawableAmount)">去提现</view>
				</view>
			</view>
		</view>
		<view class="team">
			<view class="t_title">推广团队（{{temaDetail.firstTeamCount?temaDetail.firstTeamCount:0}}）</view>
			<!-- <c-scroll-list :api="api" :apiParams="apiParams" :option="{field:'firstTeamCount'}" @load="load"> -->
			<view class="list" v-for="(v,i) in temaDetail.firstTeamList" :key="i">
				<view class="list_item">
					<view class="list_l">
						<image class="header-img"
							:src="v.avatar?vuex_imgUrl+v.avatar:'/static/common/header-img.png'" />
						<view class="l_name">{{v.nickname}}（团队{{v.secondTeamCount}}人）</view>
					</view>
					<view class="list_r">
						<view class="r_price">{{$fn.twoToFixed(v.firstPromotionAmount)}}</view>
						<view class="r_unfold" @click="openTeam(i)">
							{{v.open?"收起团队":"展开团队"}}
							<u-icon v-if="v.open" name="arrow-up" color="#2165EB" size="22rpx"></u-icon>
							<u-icon v-else name="arrow-down" color="#2165EB" size="22rpx"></u-icon>
						</view>
					</view>
				</view>

				<template v-if="v.open">
					<view class="child" v-for="(item,index) in v.secondTeamList" :key="index">
						<view class="child_l">
							<image class="child_img"
								:src="item.avatar?vuex_imgUrl+item.avatar:'/static/common/header-img.png'" />
							<view class="child_name">{{item.nickname}}</view>
						</view>
						<view class="child_r">
							{{$fn.twoToFixed(item.secondPromotionAmount)}}
						</view>
					</view>
				</template>
			</view>
			<!-- </c-scroll-list> -->

		</view>
		<c-share ref="share" />
	</view>
</template>

<script>
	export default {
		name: "promotionCenter",
		data() {
			return {
				userInfo: {
					avatar: '',
					nickname: '',
					phone: ''
				},
				balanceDetails: {},
				api: this.$api.getPromotionTeam,
				apiParams: {
					pageNum: 1,
					pageSize: 10
				},
				temaDetail: {},
			};
		},
		onLoad() {},
		onShow() {
			this.getPromotionUserFn()
			this.getPromotionTeamFn()
		},
		methods: {
			// 推广中心上半部分(用户信息)
			getPromotionUserFn() {
				this.$api.getPromotionUser().then(res => {
					console.log('推广中心上半部分(用户信息)', res);
					this.userInfo = res.data
				})
			},

			//推广中心下半部分(推广团队)
			getPromotionTeamFn() {
				this.$api.getPromotionTeam().then(res => {
					console.log('推广中心下半部分(推广团队)', res);
					res.data.firstTeamList = res.data.firstTeamList.map(v => {
						v.open=false
						return v
					})
					this.temaDetail = res.data
					
					
				})
			},

			//团队列表
			load(res) {
				console.log('团队列表', res);
			},

			// 展开团队
			openTeam(i) {
				this.temaDetail.firstTeamList[i].open = !this.temaDetail.firstTeamList[i].open
			},
			// 分享
			clickBtn() {
				console.log('去分享');
				this.$refs.share.getSharePosterFn()
			},
		}
	};
</script>

<style>
	page {
		background: #F7F7F7;
	}
</style>
<style lang="scss" scoped>
	.page {
		height: 100vh;
		display: flex;
		flex-direction: column;
		overflow: hidden;


		.promotion_bg {
			position: absolute;
			z-index: -1;
			width: 750rpx;
			height: 640rpx;
		}

		.info {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 220rpx 32rpx 0;
			box-sizing: border-box;

			.info_l {
				display: flex;
				align-items: center;
				gap: 24rpx;

				.header-img {
					width: 120rpx;
					height: 120rpx;
					border-radius: 50%;
				}

				.user {
					height: 100rpx;
					display: flex;
					flex-direction: column;
					justify-content: space-between;

					.title {
						font-weight: bold;
						font-size: 40rpx;
						color: #FFFFFF;
					}

					.phone {
						font-size: 28rpx;
						color: #FFFFFF;
					}
				}
			}

			.record {
				width: 144rpx;
				height: 56rpx;
				background: linear-gradient(90deg, #FFF3E9 0%, #FAE1C5 100%);
				border-radius: 30rpx;
				font-weight: bold;
				font-size: 24rpx;
				color: #EF4C46;
				line-height: 56rpx;
				text-align: center;
				margin: 0;
				padding: 0;
			}

		}

		.revenue {
			width: 702rpx;
			height: 200rpx;
			background: linear-gradient(137deg, #F8F3E9 0%, #FFE7BF 100%);
			border-radius: 16rpx 16rpx 0rpx 0rpx;
			margin: 40rpx auto 0;
			display: flex;
			align-items: center;
			justify-content: space-around;

			.r_item {

				.r_name {
					font-size: 24rpx;
					color: #996746;
				}

				.r_price {
					font-weight: bold;
					font-size: 40rpx;
					color: #6C2911;
					margin-top: 14rpx;
				}
			}
		}

		.cash {
			width: 702rpx;
			height: 296rpx;
			background: #FFFFFF;
			border-radius: 0rpx 0rpx 16rpx 16rpx;
			margin: 0 auto;

			.c_top {
				display: flex;
				align-items: center;
				padding: 34rpx 0 40rpx;

				.c_item {
					flex: 1;
					padding: 0 40rpx;
					box-sizing: border-box;

					.c_name {
						font-size: 24rpx;
						color: #4D4D4D;
					}

					.c_price {
						font-weight: bold;
						font-size: 36rpx;
						color: #333333;
						margin-top: 12rpx;
					}
				}

				.c_line {
					width: 1rpx;
					height: 40rpx;
					background: #996746;
				}
			}

			.c_btm {
				display: flex;
				align-items: center;
				justify-content: space-evenly;

				.c_btn {
					width: 304rpx;
					height: 88rpx;
					border-radius: 48rpx 48rpx 48rpx 48rpx;
					font-size: 36rpx;
					text-align: center;
					line-height: 88rpx;
				}

				.c_btn1 {
					border: 2rpx solid #EF4630;
					color: #EF4630;
				}

				.c_btn2 {
					background: linear-gradient(141deg, #F0A367 0%, #EF4630 100%);
					color: #FFFFFF;
				}
			}
		}

		.team {
			flex: 1;
			width: 702rpx;
			background: #FFFFFF;
			border-radius: 16rpx;
			margin: 20rpx auto;
			padding: 32rpx 24rpx;
			box-sizing: border-box;

			.t_title {
				color: #1A1A1A;
				font-size: 32rpx;
			}

			.list {

				.list_item {
					display: flex;
					align-items: center;
					justify-content: space-between;
					padding: 30rpx 0 24rpx;
					border-bottom: 1rpx solid #E6E6E6;

					.list_l {
						display: flex;
						align-items: center;
						gap: 20rpx;

						.header-img {
							width: 72rpx;
							height: 72rpx;
							border-radius: 50%;
						}

						.l_name {
							color: #1A1A1A;
							font-size: 28rpx;
						}
					}

					.list_r {
						.r_price {
							font-size: 32rpx;
							color: #EF4630;
						}

						.r_unfold {
							color: #2165EB;
							font-size: 20rpx;
							display: flex;
							align-items: center;
							margin-top: 20rpx;
							justify-content: flex-end;
						}
					}
				}



				.child {
					margin: 0 24rpx;
					padding: 28rpx 0 20rpx;
					box-sizing: border-box;
					display: flex;
					align-items: center;
					justify-content: space-between;
					border-bottom: 1rpx solid #E6E6E6;

					.child_l {
						display: flex;
						align-items: center;
						gap: 16rpx;

						.child_img {
							width: 48rpx;
							height: 48rpx;
							border-radius: 50%;
						}

						.child_name {
							color: #1A1A1A;
							font-size: 24rpx;
						}
					}

					.child_r {
						font-size: 28rpx;
						color: #EF4630;
					}
				}

			}
		}
	}
</style>